/*     */ package net.sourceforge.appgen.generator;
/*     */ 
/*     */ import java.io.File;
/*     */ import java.io.FileWriter;
/*     */ import java.io.Writer;
/*     */ import java.util.List;
/*     */ import net.sourceforge.appgen.model.Entity;
/*     */ import net.sourceforge.appgen.model.GenerationInformation;
/*     */ import org.apache.velocity.Template;
/*     */ import org.apache.velocity.VelocityContext;
/*     */ import org.apache.velocity.app.Velocity;
/*     */ 
/*     */ public class IndexFileGenerator extends OnceFileGenerator
/*     */ {
/*     */   public static final String TEMPLATE = "index.vm";
/*     */   private List<Entity> entityList;
/*  40 */   private boolean aleradyGenerate = false;
/*     */ 
/*     */   public IndexFileGenerator(GenerationInformation generationInformation, List<Entity> entityList) {
/*  43 */     super(generationInformation);
/*     */ 
/*  45 */     this.entityList = entityList;
/*     */   }
/*     */ 
/*     */   public File generateFile(Entity entity, String template, File file) throws Exception
/*     */   {
/*  50 */     Velocity.init(this.properties);
/*     */ 
/*  52 */     Template modelTemplate = Velocity.getTemplate(template);
/*     */ 
/*  54 */     VelocityContext context = new VelocityContext();
/*  55 */     context.put("entityList", this.entityList);
/*  56 */     context.put("packageName", this.packageName);
/*     */ 
/*  58 */     Writer writer = null;
/*     */     try
/*     */     {
/*  61 */       writer = new FileWriter(file);
/*     */ 
/*  63 */       modelTemplate.merge(context, writer);
/*     */     } catch (Exception e) {
/*  65 */       throw e;
/*     */     } finally {
/*  67 */       if (writer != null)
/*     */         try {
/*  69 */           writer.close();
/*     */         }
/*     */         catch (Exception localException1)
/*     */         {
/*     */         }
/*     */     }
/*  75 */     return file;
/*     */   }
/*     */ 
/*     */   public File generate(Entity entity) throws Exception
/*     */   {
/*  80 */     if (!this.aleradyGenerate) {
/*  81 */       this.aleradyGenerate = true;
/*     */ 
/*  83 */       return generateFile(entity, getTemplate(), getFile(entity));
/*     */     }
/*     */ 
/*  86 */     return null;
/*     */   }
/*     */ 
/*     */   public File getFile(Entity entity)
/*     */   {
/*  91 */     return new File(getDirectory(), "index.html");
/*     */   }
/*     */ 
/*     */   public File getDirectory()
/*     */   {
/*  96 */     return new File(this.outputDir.getPath() + File.separator + "WebContent");
/*     */   }
/*     */ 
/*     */   public String getTemplate()
/*     */   {
/* 101 */     return "index.vm";
/*     */   }
/*     */ 
/*     */   public List<Entity> getEntityList() {
/* 105 */     return this.entityList;
/*     */   }
/*     */ 
/*     */   public void setEntityList(List<Entity> entityList) {
/* 109 */     this.entityList = entityList;
/*     */   }
/*     */ }

/* Location:           C:\Users\lzl6066\Downloads\net.sourceforge.appgen_1.2.0\plugins\net.sourceforge.appgen_1.2.0.201002031718\
 * Qualified Name:     net.sourceforge.appgen.generator.IndexFileGenerator
 * JD-Core Version:    0.6.0
 */